import javax.swing.JPanel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.border.EmptyBorder;


public class VueParametrageQuotas extends Vue{
	private JTextField textFieldNbe;
	private JTextField textFieldDde;
	private JTextField textFieldMp;
	private JPanel panel;
	private JButton buttonEnregistrer;
	private JButton buttonAnnuler;

	public VueParametrageQuotas(Controleur controleur) {
		super(controleur);
		setTitle("Parametrage des quotas");
		//setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
		setBounds(100, 100, 405, 251);
		panel = new JPanel();
		
		this.addWindowListener (new WindowAdapter() {
			public void windowClosing (WindowEvent e) {
			getControleur().fermerVue(VueParametrageQuotas.this);
			}
		});
		
		panel.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(panel);
		panel.setLayout(null);
		
		JLabel lblNombreMaximumDemprunt = new JLabel("Nombre maximum d'emprunts");
		lblNombreMaximumDemprunt.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNombreMaximumDemprunt.setBounds(27, 32, 218, 15);
		panel.add(lblNombreMaximumDemprunt);
		
		textFieldNbe = new JTextField();
		textFieldNbe.setColumns(10);
		textFieldNbe.setBounds(281, 32, 86, 19);
		panel.add(textFieldNbe);
		
		JLabel lblDureDesEmprunts = new JLabel("Durée des emprunts (en jour)");
		lblDureDesEmprunts.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDureDesEmprunts.setBounds(27, 66, 218, 15);
		panel.add(lblDureDesEmprunts);
		
		textFieldDde = new JTextField();
		textFieldDde.setColumns(10);
		textFieldDde.setBounds(281, 65, 86, 19);
		panel.add(textFieldDde);
		
		buttonEnregistrer = new JButton("Enregistrer");
		
		buttonEnregistrer.addActionListener(new ActionListener() {


			public void actionPerformed(ActionEvent e) {
				String nbMaxEmprunt = textFieldNbe.getText();
				String dureeEmprunt = textFieldDde.getText();
				String montantPenalite = textFieldMp.getText();
				getControleur().nouvQuotas(nbMaxEmprunt, dureeEmprunt, montantPenalite);
				}
				
			});
		buttonEnregistrer.setBounds(260, 142, 107, 25);
		panel.add(buttonEnregistrer);
		
		buttonAnnuler = new JButton("Annuler");
		buttonAnnuler.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			getControleur().fermerVue(VueParametrageQuotas.this);}
		});
		buttonAnnuler.setBounds(260, 179, 107, 25);
		panel.add(buttonAnnuler);
		
		JLabel lblMontantDeLa = new JLabel("Montant de la pénalité par jour");
		lblMontantDeLa.setHorizontalAlignment(SwingConstants.RIGHT);
		lblMontantDeLa.setBounds(27, 101, 218, 15);
		panel.add(lblMontantDeLa);
		
		textFieldMp = new JTextField();
		textFieldMp.setEditable(true);
		textFieldMp.setBounds(281, 99, 86, 19);
		panel.add(textFieldMp);

		
	}

	public void setEtat (int etat){
		switch (etat) {
		case initiale: {	
			buttonEnregistrer.setEnabled(true);
			buttonAnnuler.setEnabled(true);
			
			break;
			}
		}
	}
	
	public void alimente(Quotas quota){
		textFieldNbe.setText(String.valueOf(quota.getNbMaxEmprunt()));
		textFieldDde.setText(String.valueOf(quota.getDureeEmprunt()));
		textFieldMp.setText(String.valueOf(quota.getMontantPenalite()));
	}
}
